package com.heima.sjms.factory;

import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

/**
 * @author 陈辉
 * @data 2023 15:12
 */

public class BeanFactory {
    private static Map springIOC;

    static {
        try {
            springIOC = new HashMap();
            Properties properties = new Properties();
            properties.load(new FileReader("day02_HashMap_ArrayList\\bean.properties"));

            Set<Object> beanNames = properties.keySet();
            for (Object beanNameObj : beanNames) {
                String beanName = beanNameObj.toString();
                String className = properties.getProperty(beanName);
                Class clazz = Class.forName(className);
                Object bean = clazz.newInstance();
                springIOC.put(beanName,bean);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static Object getBean(String beanName){
        return springIOC.get(beanName);
    }
}
